//
//  customInteraction.m
//  testTransition3
//
//  Created by zsj1992 on 17/1/4.
//  Copyright © 2017年 bjhj. All rights reserved.
//

#import "customInteraction.h"

#define SCREEN_W [UIScreen mainScreen].bounds.size.width
#define SCREEN_H [UIScreen mainScreen].bounds.size.height

@interface customInteraction()


@end

@implementation customInteraction



//有展示的控制器了
-(void)setPresentationVc:(UIViewController *)presentationVc{

    _presentationVc = presentationVc;

    [self setupBasic];


}



//基本设置
-(void)setupBasic{

    
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    
    
    [self.presentationVc.view addGestureRecognizer:pan];
    
    
    
}



-(void)handlePan:(UIPanGestureRecognizer *)recognizer{

    
    
//    
    CGPoint point = [recognizer translationInView:self.presentationVc.view];
    
    CGFloat progress = point.y/400;
    progress = fminf(fmaxf(progress, 0.0), 1.0);

//    NSLog(@"====%f",progress);

    if (progress>0) {
        
        
        if (recognizer.state == UIGestureRecognizerStateBegan) {
            
            self.interaction = YES;
            
            [self.presentationVc dismissViewControllerAnimated:YES completion:nil];
        
        }else if (recognizer.state == UIGestureRecognizerStateChanged){
            

            [self updateInteractiveTransition:progress];
            
        }else if (recognizer.state == UIGestureRecognizerStateEnded||recognizer.state==UIGestureRecognizerStateCancelled){
            
            self.interaction = NO;
            
            if (progress>0.5) {
                
                [self finishInteractiveTransition];
            }else{
            
                [self cancelInteractiveTransition];
                
            }

        }

    }
    
}


@end
